<!--
 * @Date:
 * @Author:
 * @LastEditTime:
 * @FilePath:
 * @pageName: 这是--(生产报工)--页面
-->
<template>
  <div>
    <div v-show="!noCauseDialog">
      <Navbar
        :appTitle="$route.query.type == 'edit' ? '编辑报工' : '新建报工'" @ClickRight="$router.push('/application')"/>
      <div
        class="search-content wrap-apply"
        :style="{
          top: GLOBAL.currentEnvironment ? '0' : '',
          paddingBottom: GLOBAL.currentEnvironment ? '132px' : '',
        }"
      >
        <van-cell-group style="margin-top:20px">
          <p class="label required FormTit"><span></span>工单编号</p>
          <scanInput
            v-if="showScan"
            ref="scanInput"
            :columns="orderList"
            placeholder="请选择/扫码"
            @changeScan="changeScan"
          />
          <van-field
            v-else
            readonly
            v-model="buildForm.orderCode"
            placeholder="请选择/扫码"
          />
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>生产物料</p>
          <van-field
            readonly
            v-model="buildForm.goodsName"
            placeholder="根据工单带入"
          />
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label required FormTit"><span></span>工序</p>
          <scanInput
            v-if="showScan"
            ref="scanInput2"
            :columns="processList"
            placeholder="请选择/扫码"
            @changeScan="changeScan2"
          />
          <van-field
            v-else
            readonly
            v-model="buildForm.orderCode"
            placeholder="请选择/扫码"
          />
          <div class="bottomLine" style="margin-top:2px"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label required FormTit"><span></span>操作人</p>

          <scanInputContact
            v-if="showScan"
            :columns="processList"
            ref="scanInput3"
            placeholder="请选择/扫码"
            @changeScan="changeScan3"
            :userIdText="buildForm.userIdText"
            @contactFn="handleChooseOperator"
          />

          <!-- 多选，多选的人员回填以“，”隔开。-->
          <!--             :is-link="!buildForm.userIdText" -->
          <!-- <van-field
            readonly
            name="picker"
            v-model="buildForm.userIdText"
            @click="handleChooseOperator"
            placeholder="请选择"
          >
            <div
              slot="right-icon"
              v-show="!!buildForm.userIdText"
              @click.stop="confirmOperator('', '', true)"
            >
              <img
                src="~@/assets/img/filedClear.png"
                alt=""
                style="width:0.16rem"
              />
            </div>
          </van-field> -->
          <div class="bottomLine"></div>
        </van-cell-group>

        <van-cell-group>
          <p class="label required FormTit"><span></span>合格数</p>
          <van-field v-model="buildForm.qualifiedNum" placeholder="请输入" />
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label required FormTit"><span></span>不合格数</p>
          <van-field
            v-model="buildForm.unqualifiedNum"
            readonly
            placeholder="请输入"
          />
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label  FormTit"><span></span>不合格品原因</p>
          <van-field
            readonly
            v-model="buildForm.unqualifiedNotes"
            placeholder="请选择"
            @click="fillUnqualifiedItem(buildForm)"
          />
          <div class="bottomLine"></div>
        </van-cell-group>

        <van-cell-group>
          <p class="label required FormTit"><span></span>报工时间</p>
          <van-field
            is-link
            readonly
            name="picker"
            v-model="buildForm.reportTime"
            @click="timePickShow = true"
            placeholder="请选择"
          >
          </van-field>
          <div class="bottomLine"></div>
        </van-cell-group>

        <div class="jiange-line"></div>

        <van-cell-group>
          <p class="label otherText">自定义信息</p>
          <div class="bottomLine"></div>
          <div v-for="(p, index) in formTypeExtendedFields" :key="index">
            <p class="label FormTit" :class="{ required: p.fieldMust == 2 }">
              <span></span>{{ p.fieldName }}
            </p>
            <van-field
              :placeholder="p.placeholder"
              v-model="buildForm.extDataJson[p.fieldKey]"
              :readonly="p.readonly"
              :type="p.fieldType == 3 ? 'number' : 'input'"
              :maxlength="p.fieldLength || '-'"
              :formatter="(value) => clearNoNumTwo(value, p.fieldType, p.fieldLength)"
            />
            <div class="bottomLine"></div>
          </div>
        </van-cell-group>
        <div class="search-bottoms">
          <span class="btncancel" @click="btnConfirm(true)">继续报工</span>
          <span class="btnconfirm" @click="btnConfirm()">提交</span>
        </div>
      </div>

      <!--选择报工时间 -->
      <van-popup v-model="timePickShow" position="bottom">
        <van-datetime-picker
          @confirm="confirmPick"
          v-model="happenTime"
          @cancel="cancelPick"
          type="datetime"
          title="报工时间"
          :formatter="formatter"
        />
      </van-popup>

      <!--不合格项组件-->
      <unqualified-item-dialog
        ref="unqualifiedItemDialog"
        :unqualifiedItemList="unqualifiedItemList"
        @getValue="getValue($event)"
      ></unqualified-item-dialog>
      <!-- 操作按钮弹窗-->
      <van-popup v-model="showPicker" round position="bottom">
        <van-picker
          show-toolbar
          :columns="processList"
          @cancel="showPicker = false"
          @confirm="onConfirm"
          value-key="key"
        />
      </van-popup>

      <!--操作人组件-->
      <contact-pickers
        :visible="userSelectVisible"
        @closePicker="userSelectVisible = false"
        @confirm="selectOperator"
      >
      </contact-pickers>
    </div>

    <!-- 不合格原因组件 -->
    <noCause
      v-show="noCauseDialog"
      @noCauseConfirm="noCauseConfirm"
      @noCauseCancel="noCauseCancel"
    ></noCause>
  </div>
</template>
<script>
import moment from "moment";
import Navbar from "@/components/navBar/navBar_right";
import scanInput from "@/components/scanCode/scanInput";
import scanInputContact from "@/components/scanCode/scanInputContact";
import upload from "@/components/upload/upload";
import VanFieldSelectPicker from "@/components/ActionSheet/VanFieldSelectPicker";
import Examine from "@/components/examine";
import {
  processByBatchId,
  productionReportingAdd,
  productionTaskProcessMessage,
  workOrderDetailQueryById,
  workOrderList,
  scheduleById,
  produceOrderReportWorkQueryById,
  produceOrderReportWorkEdit,
  produceOrderReportWorkWorkbench,
} from "@/api/productionApply";
import { formTypeExtendedFieldList } from "@/api/mobile";
import ContactPickers from "@/components/choiceuse/ContactPickers.vue";
import unqualifiedItemDialog from "@/views/workManagement/components/unqualifiedItemDialog.vue";
import { getUnqualifiedReasonList2, queryProcess } from "@/api/system";
import noCause from "@/views/workManagement/productTask/noCause.vue";
import { Tip as Tips } from "@/utils";
import { getAction } from "@/api/manage";
export default {
  name: "newOutsourcingReport",
  components: {
    unqualifiedItemDialog,
    ContactPickers,
    upload,
    VanFieldSelectPicker,
    Navbar,
    scanInput,
    Examine,
    noCause,
    scanInputContact,
  },
  data() {
    return {
      userIdList: [],
      realnameList: [],
      userIdScanList: [],
      detailInfo: {},
      sequentially: false,
      formTypeExtendedFields: [],
      happenTime: new Date(),
      timePickShow: false,
      noCauseDialog: false,
      unqualifiedItemDialog: false,
      showPicker: false,
      userSelectVisible: false, // 操作人选择组件
      buildForm: {
        unqualifiedNum: 0,
        qualifiedNum: "",
        extDataJson: {},
      },
      unqualifiedItemModal: false, // 填写不合格项数量
      unqualifiedItemList: [], // 不合格项列表
      orderList: [],
      columns: [],
      processList: [],
      showScan: false,
    };
  },
  computed: {},
  beforeRouteLeave(to, from, next) {
    if (this.showPeopleSlect) {
      this.$refs.examine.closePicker();
      next(false);
    } else {
      next();
    }
  },
  async created() {
    // 获取出入库自定义表单字段;
    formTypeExtendedFieldList({ formType: 4 }).then((res) => {
      if (res.code == 200 && res.result) {
        this.formTypeExtendedFields = res.result;
      }
    });
    this.getInitData();

    this.showScan = true;

    // 扫工单码进入
    if (this.$route.query.formPage == "scanCode" && this.$route.query.code) {
      this.changeScan({code: this.$route.query.code}, "scan");
    } 
    if(this.$route.query.codeType == 'productTask'){
      this.changeScan2({code: this.$route.query.code}, "scan");
    }
    
    // else if (this.$route.query.fromPage === "productionTask") {
    //   this.showScan = false;
    //   this.buildForm.orderCode = this.$route.query.item.orderCode;
    //   this.buildForm.processId = this.$route.query.item.processesId;
    //   this.buildForm.processName = this.$route.query.item.processesCode;
    //   this.buildForm.goodsName =
    //       this.$route.query.item.goodsName +
    //       "-" +
    //       this.$route.query.item.goodsCode;
    //   this.buildForm.orderId = this.$route.query.item.orderId;
    //   this.buildForm.goodsId = this.$route.query.item.goodsId;
    // } else if (this.$route.query.fromPage === "home") {
    //   this.showScan = true;
    // } else if (this.$route.query.fromPage === "tabbar") {
    //   console.log('tabbar扫码结果：', this.$route.query.id)
    //   //   tabbar的扫码直接扫批次码报工，根据批次id回填工序(移动端批次报工扫码)
    //   let batchId = this.$route.query.id
    //   this.getBatchList(batchId)
    // }
  },

  mounted() {},
  methods: {
    clearNoNumTwo(value, type, length) {
      if(type != 3) {
        return value
      }else {
        return value.replace(/[^\d]/g, '')
      }
    },
    formatter(type, val) {
      console.log(type);
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      if (type === "hour") {
        return val + "时";
      }
      if (type === "minute") {
        return val + "分";
      }
      if (type === "second") {
        return val + "秒";
      }
      
      return val;
    },

    // 确定选择时间
    confirmPick(date) {
      this.buildForm.reportTime = moment(date).format("YYYY-MM-DD HH:mm:ss");
      this.timePickShow = false;
    },
    // 取消选择时间
    cancelPick() {
      this.timePickShow = false;
    },
    noCauseConfirm(list, total) {
      this.noCauseDialog = false;
      this.buildForm.unqualifiedNum = total;
      this.buildForm.unqualifiedNotes = list
        .map((item) => item.nonconformityDescribe + ":" + item.num)
        .join(",");
      this.buildForm.produceOrderReportWorkNonconformityDetail = list.map(
        (item) => {
          return {
            nonconformityNum: item.num,
            nonconformityId: item.id,
          };
        }
      );
      this.$forceUpdate();
    },
    noCauseCancel() {
      this.noCauseDialog = false;
    },
    // 根据批次id获取对应批次下的工序
    getBatchList(id) {
      processByBatchId({ id }).then((res) => {
        let processList = res.result;
        //   找到sort最大值的工序，根据工序id查询对应工单的信息回填
        // 使用reduce方法查找最大排序值的项
        let maxItem = processList.reduce(function(prev, current) {
          return prev.sort > current.sort ? prev : current;
        });
        console.log(maxItem);
        this.buildForm.processName = maxItem.processesName;
        this.getOrderInfo(maxItem.id);
      });
    },
    getOrderInfo(id) {
      productionTaskProcessMessage({ id }).then((rst) => {
        console.log(rst);
        this.buildForm.orderId = rst.result.orderId;
        this.buildForm.orderCode = rst.result.orderCode;
        this.buildForm.goodsName =
          rst.result.goodsName + "-" + rst.result.goodsCode;
        this.buildForm.orderCode = rst.result.orderCode;
        this.buildForm.processName = rst.result.processesCode;
        this.buildForm.goodsName =
          rst.result.goodsName + "-" + rst.result.goodsCode;
        this.buildForm.orderId = rst.result.id;
        this.buildForm.goodsId = rst.result.goodsId;
        this.buildForm.goodsBasicUnit = rst.result.goodsBasicUnit;
        this.processList = rst.result.processList.map((item) => {
          return {
            label: item.processesName,
            key: item.processesName,
            value: item.id,
          };
        });
        // let scanObj = {
        //   id: this.buildForm.deviceId,
        //   orderCode: `${res.result.deviceCode}-${res.result.deviceName}`,
        // };
        // this.$refs.scanInput.propValue(scanObj);
      });
    },
    fillUnqualifiedItem() {
      this.noCauseDialog = true;
    },
    getValue(query) {
      this.buildForm.unqualifiedQuantityNum = query.sum;
      this.buildForm.unqualifiedReason = query.sum2;
      this.buildForm.unqualifiedDtos = query.unqualifiedList.map((item) => {
        return {
          id: item.id,
          num: item.num,
        };
      });
    },
    onConfirm(a, b) {
      console.log(a, b, "ab");
      if (typeof a == "undefined") {
        this.showPicker = false;
        return;
      }
      this.buildForm.processId = a.value;
      this.buildForm.processName = a.key;
      this.showPicker = false;
    },
    handleChooseOperator(index, item) {
      this.currentIndex = index;
      this.userSelectVisible = true;
    },
    confirmOperator(v) {
      console.log(v);
      if (!v) {
        console.log(v);
        this.buildForm.userId = "";
        this.buildForm.userIdText = "";
        this.$forceUpdate();
      } else {
        console.log(2);
        this.buildForm.userId = v;
        this.buildForm.userIdText = v.join(",");
      }
    },

    selectOperator(val, selectedList) {
      console.log(val, selectedList);
      this.userSelectVisible = false;
      if (selectedList.length) {
        this.buildForm.userId = val;
        this.buildForm.userIdText = selectedList
          .map((item) => item.realname)
          .join(",");
      }
    },
    //页面加载请求数据
    async getInitData() {
      const that = this;
      const WorkOrderRes = await workOrderList({
        orderStatus: 1,
        pageNo: 1,
        pageSize: 100000,
      });
      if (WorkOrderRes && WorkOrderRes.code == 200) {
        this.orderList = WorkOrderRes.result.records.map((item) => {
          return {
            key: item.orderCode,
            value: item.id,
          };
        });

        if (this.$route.query.type == "edit") {
          produceOrderReportWorkQueryById({
            id: this.$route.query.item.id,
          }).then((res) => {
            if (res.code == 200) {
              this.detailInfo = res.result;

              // 回显自定义信息
              for (let j in res.result.extDataJson) {
                this.buildForm.extDataJson[j] = res.result.extDataJson[j];
              }

              this.buildForm.orderId = res.result.orderId;
              this.buildForm.orderCode = res.result.orderCode;
              this.$refs.scanInput.formData.value = res.result.orderId; //回显工单
              this.$refs.scanInput.formData.key = res.result.orderCode; //回显工单
              //回显物料
              this.buildForm.goodsName =
                res.result.serialNumber +
                " | " +
                res.result.serialName +
                " | " +
                res.result.serialSpecifications;

              //  回显操作人
              this.buildForm.userIdText = res.result.userText;
              this.buildForm.userId = res.result.userId;

              // 回显合格数
              this.buildForm.qualifiedNum = res.result.qualifiedNum;

              // 回显不合格数
              this.buildForm.unqualifiedNum = res.result.unqualifiedNum;

              // 回显报工时间
              this.buildForm.reportTime = res.result.reportTime;

              // 回显不合格原因
              this.buildForm.unqualifiedNotes =
                res.result.nonconformityDescribe;

              // 获取工序列表
              workOrderList({
                pageNo: 1,
                pageSize: 9999,
                orderCode: this.buildForm.orderCode,
              }).then((res2) => {
                if (res2.code == 200) {
                  this.processList = res2.result.records[0].produceOrderTaskVo.map(
                    (item) => {
                      return {
                        label: item.processesName,
                        key: item.processesName,
                        value: item.processesId,
                        taskId: item.taskId,
                      };
                    }
                  );
                  this.$refs.scanInput2.formData.value = res.result.processesId; //回显工序
                  this.$refs.scanInput2.formData.key = res.result.processesName; //回显工序
                }
              });

              this.buildForm.processesId = res.result.processesId;
              this.buildForm.processesName = res.result.processesName;
              this.buildForm.taskId = res.result.taskId;

              this.$refs.scanInput.showPicker = true;
              this.$refs.scanInput.showPicker = false;
              this.$refs.scanInput2.showPicker = true;
              this.$refs.scanInput2.showPicker = false;
              this.$forceUpdate();
            } else {
              this.$toast(res.message);
            }
          });
        }
      }

      getUnqualifiedReasonList2({ pageNo: 1, pageSize: 100000 }).then((res) => {
        this.unqualifiedItemList = (res || []).map((item) => {
          return {
            label: item.unqualifiedName,
            id: item.id,
            num: "",
          };
        });
      });

      // const res = await queryProcess();
      // console.log(res);
      // res.result.records.forEach((item) => {
      //   item.label = item.processesName
      //   item.key = item.processesName
      //   item.value = item.id
      // });
      // this.processList = res.result.records;
    },

    changeScan(v, opratorType) {
      console.log(v, opratorType, "获取扫码组件数据");
      //value是下拉选择后值,code是扫码获得的值，根据qrcode判断是否隐藏当前页面只显示相机页
      if (opratorType == "select" && this.buildForm.orderId != v.value) {
        this.buildForm.orderId = v.value;
        this.buildForm.orderCode = v.key || "-";

        this.$refs.scanInput2.formData.value = undefined;
        this.$refs.scanInput2.formData.key = undefined;
        this.buildForm.processesId = "";
        this.buildForm.processesName = "";
        this.buildForm.taskId = "";

        workOrderList({
          pageNo: 1,
          pageSize: 9999,
          orderCode: this.buildForm.orderCode,
        }).then((res) => {
          if (res.code == 200) {
            this.buildForm.goodsName =
              res.result.records[0].serialNumber +
              " | " +
              res.result.records[0].serialName +
              " | " +
              res.result.records[0].serialSpecifications;

            this.processList = res.result.records[0].produceOrderTaskVo.map(
              (item) => {
                return {
                  label: item.processesName,
                  key: item.processesName,
                  value: item.processesId,
                  taskId: item.taskId,
                };
              }
            );
          }
        });
      }
      if (opratorType == "scan") {

        console.log(v.code);
        if (v.code.EntityType !== "workOrder") {
          this.$toast("请扫正确二维码");
          return;
        }
        let obj = {
          id: v.code.id, //
        };
        workOrderList(obj).then((res) => {
          if (res.code == 200) {
            if (res.result.records[0].orderStatus != 1) {
              this.$toast("工单状态不正确");
              return;
            }
            this.buildForm.orderId = res.result.records[0].orderId;
            this.buildForm.orderCode = res.result.records[0].orderCode;

            this.$refs.scanInput2.formData.value = undefined;
            this.$refs.scanInput2.formData.key = undefined;

            this.$refs.scanInput.formData.value = res.result.records[0].orderId;
            this.$refs.scanInput.formData.key = res.result.records[0].orderCode;
            this.$refs.scanInput.showPicker = true;
            this.$refs.scanInput.showPicker = false;
            this.buildForm.goodsName =
              res.result.records[0].serialNumber +
              " | " +
              res.result.records[0].serialName +
              " | " +
              res.result.records[0].serialSpecifications;

            this.processList = res.result.records[0].produceOrderTaskVo.map(
              (item) => {
                return {
                  label: item.processesName,
                  key: item.processesName,
                  value: item.processesId,
                  taskId: item.taskId,
                };
              }
            );
          }
        });
      }
    },

    changeScan2(v, opratorType) {
      console.log(v, opratorType, "获取扫码组件数据");
      //value是下拉选择后值,code是扫码获得的值，根据qrcode判断是否隐藏当前页面只显示相机页
      if (opratorType == "select" && this.buildForm.processesId != v.value) {
        console.log(v, "vvvvvvvvvvvvvvvvvvv");
        this.buildForm.processesId = v.value;
        this.buildForm.processesName = v.key || "-";
        this.buildForm.taskId = v.taskId;
        scheduleById({ id: v.taskId }).then((res) => {
          if (res.code == 200) {
            this.buildForm.qualifiedNum = res.result.reportWorkNum;
            this.$forceUpdate();
          }
        });
      }
      if (opratorType == "scan") {
        console.log(v.code);
        if (v.code.EntityType !== "productTask") {
          this.$toast("请扫正确二维码");
          return;
        }
        let obj = {
          id: v.code.id,
        };
        produceOrderReportWorkWorkbench(obj).then((res) => {
          if (res.code == 200) {
            if (res.result.orderStatus != 1) {
              this.$toast("工单状态不正确");
              return;
            }

            this.$refs.scanInput.formData.value = res.result.orderId;
            this.$refs.scanInput.formData.key = res.result.orderCode;

            this.$refs.scanInput2.formData.value = res.result.processesId;
            this.$refs.scanInput2.formData.key = res.result.processesName;

            workOrderList({
              pageNo: 1,
              pageSize: 9999,
              orderCode: res.result.orderCode,
            }).then((res) => {
              if (res.code == 200) {
                this.buildForm.goodsName =
                  res.result.records[0].serialNumber +
                  " | " +
                  res.result.records[0].serialName +
                  " | " +
                  res.result.records[0].serialSpecifications;

                this.$forceUpdate();

                // this.processList = res.result.records[0].produceOrderTaskVo.map(
                //   (item) => {
                //     return {
                //       label: item.processesName,
                //       key: item.processesName,
                //       value: item.processesId,
                //       taskId: item.taskId,
                //     };
                //   }
                // );
              }
            });

            this.buildForm.processesId = res.result.processesId;
            this.buildForm.processesName = res.result.processesName;
            this.buildForm.taskId = v.code.id;

            this.$refs.scanInput.showPicker = true;
            this.$refs.scanInput.showPicker = false;
            this.$refs.scanInput2.showPicker = true;
            this.$refs.scanInput2.showPicker = false;

            scheduleById({ id: v.code.id }).then((res) => {
              if (res.code == 200) {
                this.buildForm.qualifiedNum = res.result.reportWorkNum;
                this.$forceUpdate();
              }
            });

            // let scanObj = {
            //   id: this.buildForm.deviceId,
            //   orderCode: `${res.result.orderCode}`,
            // };
            // this.$refs.scanInput2.propValue(scanObj);
          } else {
            Tips.error(res.message);
          }
        });
      }
    },
    changeScan3(v, opratorType) {
      if (opratorType == "scan") {
        console.log(v.code);
        if (v.code.EntityType !== "printTask") {
          this.$toast("请扫正确二维码");
          return;
        }

        if (this.userIdScanList.indexOf(v.code.userid) !== -1) {
          this.$toast("该用户已存在");
          return;
        } else {
          this.userIdScanList.push(v.code.userid);
        }

        getAction("/sys/user/queryById", { id: v.code.userid }).then((res) => {
          if (res.code == 200) {
            this.realnameList.push(res.result.realname);
            this.userIdList.push(res.result.id);
            this.buildForm.userIdText = this.realnameList.join(",");
            this.buildForm.userId = this.userIdList.join(",");
            this.$forceUpdate();
          }
        });
      }
    },
    fileChange(ids) {
      this.buildForm.attachment = ids;
      console.log("父组件" + ids); //你要保存的fileids
    },
    // 提交
    btnConfirm(val) {
      if (val) {
        // 继续报工
        this.sequentially = true;
      }
      if (!this.buildForm.orderCode) {
        this.$toast("请选择工单编号");
        return;
      }
      if (!this.buildForm.processesId && !this.buildForm.processesName) {
        this.$toast("请选择工序");
        return;
      }
      if (!this.buildForm.userId) {
        this.$toast("请选择操作人");
        return;
      }
      if (!this.buildForm.qualifiedNum) {
        this.$toast("请输入合格数");
        return;
      }
      if (!this.buildForm.unqualifiedNum) {
        this.$toast("请输入不合格数");
        return;
      }
      if (!this.buildForm.reportTime) {
        this.$toast("请选择报工时间");
        return;
      }

      this.handleSubmit();
    },
    handleSubmit() {
      let params = {
        ...this.buildForm,
      };

      if (this.$route.query.type == "edit") {
        // 编辑
        produceOrderReportWorkEdit({
          ...params,
          id: this.$route.query.item.id,
        }).then((res) => {
          if (res.success) {
            this.$toast("编辑成功");
            setTimeout(() => {
              if (!this.sequentially) {
                this.$router.back();
              } else {
                scheduleById({ id: this.buildForm.taskId }).then((res) => {
                  if (res.code == 200) {
                    this.buildForm.qualifiedNum = res.result.reportWorkNum;
                    this.$forceUpdate();
                  }
                });
              }
            }, 500);
          } else {
            this.$toast(res.message);
          }
        });
      } else {
        // 新增
        productionReportingAdd(params).then((res) => {
          if (res.success) {
            this.$toast("报工成功");
            setTimeout(() => {
              if (!this.sequentially) {
                this.$router.back();
              } else {
                scheduleById({ id: this.buildForm.taskId }).then((res) => {
                  if (res.code == 200) {
                    this.buildForm.qualifiedNum = res.result.reportWorkNum;
                    this.$forceUpdate();
                  }
                });
              }
            }, 500);
          } else {
            this.$toast(res.message);
          }
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/theme.scss";

.jiange-line{
  height: 20px;
  background-color: #F5F5F5;
}
.required span::after{
  left: -20px;
  top: 3px;
}
.search-content {
  position: fixed;
  top: 110px;
  width: 100%;
  height: calc(100vh - 180px);
  background: #fff;
  overflow: scroll;
  z-index: 99;
  padding-bottom: 50px;

  .formgroup {
    background: #ffffff;
    // padding: 0 0.16rem;
    margin-top: 20px;
    margin-bottom: 40px;
    padding-top: 20px;

    .title {
      width: 116px;
      height: 28px;
      font-size: 30px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #191f25;
      line-height: 10px;
      margin-left: 32px;
    }
  }
}

.bottomLine {
  height: 2px;
  background-color: #f0f0f0;
  margin: 0 32px;
}

.otherText {
  padding-bottom: 32px;
  font-size: 32px;
  font-weight: bold;
  color: #191f25;
}

.haveUnitBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding-right: 32px;

  /deep/ .van-cell {
    padding-right: 0;
    width: 520px;
  }

  /deep/ .van-field__control {
    max-width: 600px;
  }
}

/deep/ .van-nav-bar {
  z-index: 99;
}

.search-bottoms {
  width: 100%;
  height: 100px;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  bottom: 0px;
  padding: 0 22px;
  box-sizing: border-box;
  font-size: 32px;
  font-weight: 500;
  z-index: 9;

  .btncancel {
    flex: 1;
    background: #f6f6f6;
    border: 2px solid rgba(25, 31, 37, 0.12);
    box-sizing: border-box;
    height: 78px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    margin-right: 22px;
    color: #191f25;
  }

  .btnconfirm {
    flex: 1;
    background: #1890ff;
    box-sizing: border-box;
    height: 79px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    color: #ffffff;
  }
}
</style>
